#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
============================================
    @author: Curry 
    @file: regs.py
    @time: 2024/1/16 13:45
    @email:Curry_30_yf@163.com
    @des ： 前端页面获取到数据，插入到数据库中
 ============================================   
"""
import pymysql
from flask import Flask, request, render_template

app = Flask(__name__, template_folder='test2')

conn = pymysql.connect(host='localhost', user='root', password='root', database='house')
print("数据库成功连接")
cursor = conn.cursor()
print("游标创建成功")

@app.route('/')
def tes():
    return  render_template('reg.html')

@app.route('/register/', methods=['GET', 'POST'])
def register():
    # 获取表单中具体的某值
    username = request.form['username']   # 姓名
    password = request.form['password']   # 密码
    birthday = request.form['birthday']   # 生日
    gender = request.form['gender']       # 性别
    hobby = request.form['hobby']         # 爱好
    homeland = request.form['homeland']   # 居住地
    self_info = request.form['self_info'] # 自我介绍
    print(type(birthday))
    # print(username,password,birthday,gender,hobby,homeland,self_info)
    sql = "INSERT INTO user(username, password, birthday, gender, hobby, homeland, self_info) VALUES ('{}','{}','{}','{}','{}','{}','{}');".format(username, password, birthday, gender, hobby, homeland, self_info)
    cursor.execute(sql)



    # va = request.form # 获取form表单提交过来的非文件数据,类似字典
    # for item in va.values():
    #     print(item)
    # avatar_obj = request.files.get('avatar')  #获取文件，类似字典
    # avatar_obj.save(avatar_obj.name)    # 保存文件
    conn.commit()
    return '注册成功'


if __name__ == '__main__':
    app.run(debug=True)
